<template>
	<view>
		<uni-list>
			<uni-list-item v-for="(item, index) in autoDataList" :key="index" :show-extra-icon="true" showArrow
				:title="item.title" clickable="true" :extra-icon="extraIcon" :note="item.dataTime"
				@click="jump(item)" />
		</uni-list>
		<uni-list>
			<uni-list-item v-for="(item, index) in repairDataList" :key="index" :show-extra-icon="true" showArrow
				:title="item.title" clickable="true" :extra-icon="extraIcon" :note="item.dataTime"
				@click="jump(item)" />
		</uni-list>
	</view>
</template>

<script>
	export default {
		name: "autoApprovalPending",
		data() {
			return {
				autoDataList: [],
				repairDataList:[],
				extraIcon: {
					color: '#409EFF',
					size: '40',
					type: 'email-filled'
				},
			};
		},
		methods: {
			getAutoTodoList() {
				uni.request({
					url: "http://localhost:8088/getTodoUndoneList?userId=" + localStorage.getItem("userId"),
					method: "GET",
					success: (res) => {
						if (res.data && res.data.code === '0') {
							const todoList = res.data.data;

							// Filter todo items based on conditions
							this.autoDataList = todoList
								.filter(item => item.todoType === '用车申请综合办审批' && item.todoStatus === '未完成')
								.map(item => ({
									title: '您有一条用车审批待处理',
									dataTime: item.todoTime,
									orderId: item.orderId,
									// Other properties according to your needs
								}));
						} else {
							console.error('Error fetching data. Server response:', res);
						}
					},
					fail: (error) => {
						console.error('Error fetching data:', error);
					}
				});
			},
			getRepairTodoList() {
				uni.request({
					url: "http://localhost:8088/getTodoUndoneList?userId=" + localStorage.getItem("userId"),
					method: "GET",
					success: (res) => {
						if (res.data && res.data.code === '0') {
							const todoList = res.data.data;

							// Filter todo items based on conditions
							this.repairDataList = todoList
								.filter(item => item.todoType === '维修申请综合办审批' && item.todoStatus === '未完成')
								.map(item => ({
									title: '您有一条维修审批待处理',
									dataTime: item.todoTime,
									orderId: item.orderId,
									// Other properties according to your needs
								}));
						} else {
							console.error('Error fetching data. Server response:', res);
						}
					},
					fail: (error) => {
						console.error('Error fetching data:', error);
					}
				});
			},

			jump(item) {
				// Directly access the title property of the item
				const title = item.title;

				// Navigate to the corresponding page based on the title
				if (title === "您有一条用车审批待处理") {
					uni.navigateTo({
						url: "/pages/autoGeneralApproval/autoGeneralApproval?orderId=" + item.orderId
					});
				} else if (title === "您有一条维修审批待处理") {
					uni.navigateTo({
						url: "/pages/repairGeneralApproval/repairGeneralApproval?orderId=" + item.orderId
					});
				}
				// You can add more conditions for other titles and corresponding pages
			}
		},
		created() {
			this.getAutoTodoList();
			this.getRepairTodoList();
		},
	};
</script>

<style lang="scss">
	.slot-box {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.slot-image {
		display: block;
		margin-right: 10px;
		width: 30px;
		height: 30px;
	}

	.slot-text {
		flex: 1;
		font-size: 14px;
		color: #4cd964;
		margin-right: 10px;
	}
</style>